package cn.com.backstage.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


import cn.com.api.service.ApiU_coupon_detailService;
import cn.com.backstage.controller.base.U_coupon_detailBaseController;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_BACKSTAGE+"/")
public class U_coupon_detailController  extends U_coupon_detailBaseController {

	private static Logger logger = Logger.getLogger(U_coupon_detailController.class);
	
	@Autowired
	private ApiU_coupon_detailService apiU_coupon_detailService;
	
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "coupon_detail-list")
	public ModelAndView u_coupon_detail_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_coupon_detail_list.jsp");
		Map<String, Object> param = new HashMap<String, Object>();
		String coupon_cate_id = request.getParameter("coupon_cate_id");
		String coupon_amout = request.getParameter("coupon_amout");
		String sdate = request.getParameter("sdate");
		String edate = request.getParameter("edate");

		if(coupon_cate_id != null && !"-1".equals(coupon_cate_id)){			
			param.put("coupon_cate_id", coupon_cate_id);
			mv.addObject("coupon_cate_id", coupon_cate_id);
		}
		if(coupon_amout != null && !"-1".equals(coupon_amout)){			
			param.put("coupon_amout", coupon_amout);
			mv.addObject("coupon_amout", coupon_amout);
		}
		if(sdate != null){	
			param.put("sdate", sdate);
			mv.addObject("sdate", sdate);
		}
		if(edate != null){	
			param.put("edate", edate);
			mv.addObject("edate", edate);
		}
		List<Map<String, Object>> u_coupon_details = apiU_coupon_detailService.findU_coupon_detailsByCondition(param);
		
		List<Map<String, Object>> u_coupon_amount = apiU_coupon_detailService.findU_coupon_amountByCondition(param);
		int usenum = apiU_coupon_detailService.findU_coupon_usenum(param);
		int allnum = apiU_coupon_detailService.findU_coupon_allnum(param);
		mv.addObject("u_coupon_details", u_coupon_details);
		mv.addObject("u_coupon_amount", u_coupon_amount);
		mv.addObject("usenum", usenum);
		mv.addObject("surplusnum", allnum - usenum);
		return mv;
	}
	
	
	@RequestMapping(value = "coupon_detail_amount-list")
	public ModelAndView coupon_detail_amount_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_coupon_detail_list.jsp");
		Map<String, Object> param = new HashMap<String, Object>();
		String coupon_cate_id = request.getParameter("coupon_cate_id");
		if(coupon_cate_id != null && !"-1".equals(coupon_cate_id)){			
			param.put("coupon_cate_id", coupon_cate_id);
			mv.addObject("coupon_cate_id", coupon_cate_id);
		}
		List<Map<String, Object>> u_coupon_amount = apiU_coupon_detailService.findU_coupon_amountByCondition(param);
		mv.addObject("u_coupon_amount", u_coupon_amount);
		return mv;
	}
	

}



